package cn.ekuma.epos.android.finder;

import java.util.ArrayList;
import java.util.List;

import android.app.ProgressDialog;
import android.view.View;
import com.openbravo.bean.Customer;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.query.QBFParameter;
import com.openbravo.data.loader.query.QBFParameters;

import cn.ekuma.data.dao.I_DataLogic;
import cn.ekuma.data.ui.android.AbstractViewBeanListAdapter;
import  cn.ekuma.data.ui.android.AbstractListFinderActivate;
import cn.ekuma.epos.android.adapter.CustomerListAdapter;
import cn.ekuma.epos.datalogic.DataLogicPDA;
import cn.ekuma.epos.db.table.I_Customer;

public class CustomerFinderActivate extends AbstractListFinderActivate<Customer>{

	 public CustomerFinderActivate() {
		super(DataLogicPDA.getDataLogic());
		// TODO Auto-generated constructor stub
	}

	QBFParameter  nameLike=new QBFParameter(I_Customer.NAME);
	
	@Override
	public AbstractViewBeanListAdapter getListAdapter() {
		return new CustomerListAdapter(this);
	}

	@Override
	public void initAdvSeachView() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean isQuickSeachAble() {
		return true;
	}
	
	@Override
	public void filterParaReset() {

	}

	@Override
	public void onQuickSeach(String sCode) {
		final QBFParameters paras=new QBFParameters();
		paras.or(new QBFParameter(I_Customer.CARD).equal(sCode))
		     .or(new QBFParameter(I_Customer.CITY).equal(sCode))
		     .or(new QBFParameter(I_Customer.POSTAL).equal(sCode))
		     .or(new QBFParameter(I_Customer.NAME1).link(sCode))
		     .or(new QBFParameter(I_Customer.COUNTRY).equal(sCode))
		     .or(new QBFParameter(I_Customer.CITY).equal(sCode))
		     .or(new QBFParameter(I_Customer.SEARCHKEY).link(sCode))
		     .or(new QBFParameter(I_Customer.REGION).equal(sCode)) 
		     .or(new QBFParameter(I_Customer.FAX).equal(sCode)) 
		     .or(new QBFParameter(I_Customer.PHONE).equal(sCode))
		     .or(new QBFParameter(I_Customer.PHONE2).equal(sCode))
		     .or(new QBFParameter(I_Customer.ADDRESS).equal(sCode));
		
		final ProgressDialog dialog = ProgressDialog.show(this, "", 
		        "查旬中，请稍等 …", true, true);
		new Thread(){
			
			public void run(){
				I_DataLogic dlERP=DataLogicPDA.getDataLogic();
				try {
					List<Customer> lists=dlERP.queryByQBFParameters(Customer.class.getName(), paras);
					if(lists==null)
						lists=new ArrayList();
					mHandler.obtainMessage(MSG_SUCCESS, lists).sendToTarget();			
				} catch (BasicException e) {
					e.printStackTrace();
					mHandler.obtainMessage(MSG_FAILURE).sendToTarget();//获取图片失败   
				}
				dialog.dismiss(); 
			}
			}.start();		
	}
	

	@Override
	public View createFilterPanel() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public View createAdvFilterPanel() {
		// TODO Auto-generated method stub
		return null;
	}


}
